package com.jz.community.basecomm.net.retrofit;


import com.jz.community.basecomm.bean.baseCommInfo.BaseEmbedded;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.basecomm.utils.LoggerUtils;
import com.jz.community.basecomm.utils.Preconditions;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


/**
 * Created by Tony.Fan on 2018/4/15 17:54
 * <p>
 * 基本 Rx Observer
 */
public abstract class BaseRxObserver<T> implements Observer<BaseEmbedded<T>>, OnLoadListener<T> {

    @Override
    public void onFail(String s, int code) {
    }

    @Override
    public void onNext(BaseEmbedded<T> baseEmbedded) {
        T t = baseEmbedded.get_embedded();
        if (!Preconditions.isNullOrEmpty(t)) {
            onSuccess(t);
        }
    }

    @Override
    public void onError(Throwable e) {
        onFail(ApiException.handleException(e).message, ApiException.handleException(e).code);
    }

    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onComplete() {

    }
}

